package org.xxpay.core.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.xxpay.core.common.util.DateUtil;

import java.io.Serializable;
import java.util.Date;

public class PayAlizftSettRecord implements Serializable {

    /* 拼接申请数据  **/
    public void appendApplyInfo(String oldVal, String applyResult) {

        JSONArray array = new JSONArray();

        if(StringUtils.isNotEmpty(oldVal)){
            array = JSONArray.parseArray(oldVal);
        }

        if(applyResult == null){
            return ;
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("applyTime", DateUtil.date2Str(new Date()));
        jsonObject.put("applyResult", applyResult);
        array.add(jsonObject);
        this.applyInfo = array.toJSONString();
    }



    /**
     * 结算ID
     *
     * @mbg.generated
     */
    private Long id;

    /**
     * 支付订单号
     *
     * @mbg.generated
     */
    private String payOrderId;

    /**
     * 支付金额,单位分
     *
     * @mbg.generated
     */
    private Long payOrderAmount;

    /**
     * 商品标题
     *
     * @mbg.generated
     */
    private String payOrderSubject;

    /**
     * 渠道订单号 如果为空有可能是补单任务
     *
     * @mbg.generated
     */
    private String channelOrderNo;

    /**
     * 支付宝二级商户编码
     *
     * @mbg.generated
     */
    private String smid;

    /**
     * 二级商户ID -1表示该商户数据已删除， 不影响正常结算
     *
     * @mbg.generated
     */
    private Long subMchId;

    /**
     * 通道模板账号ID -1表示该商户数据已删除， 不影响正常结算
     *
     * @mbg.generated
     */
    private Long passageTemplateId;

    /**
     * 结算状态,1-待结算,2-结算中,3-结算成功,4-结算失败
     *
     * @mbg.generated
     */
    private Byte status;

    /**
     * 重试次数
     *
     * @mbg.generated
     */
    private Integer retryCount;

    /**
     * 创建时间
     *
     * @mbg.generated
     */
    private Date createTime;

    /**
     * 更新时间
     *
     * @mbg.generated
     */
    private Date updateTime;

    /**
     * 调起接口信息
     *
     * @mbg.generated
     */
    private String applyInfo;

    private static final long serialVersionUID = 1L;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPayOrderId() {
        return payOrderId;
    }

    public void setPayOrderId(String payOrderId) {
        this.payOrderId = payOrderId;
    }

    public Long getPayOrderAmount() {
        return payOrderAmount;
    }

    public void setPayOrderAmount(Long payOrderAmount) {
        this.payOrderAmount = payOrderAmount;
    }

    public String getPayOrderSubject() {
        return payOrderSubject;
    }

    public void setPayOrderSubject(String payOrderSubject) {
        this.payOrderSubject = payOrderSubject;
    }

    public String getChannelOrderNo() {
        return channelOrderNo;
    }

    public void setChannelOrderNo(String channelOrderNo) {
        this.channelOrderNo = channelOrderNo;
    }

    public String getSmid() {
        return smid;
    }

    public void setSmid(String smid) {
        this.smid = smid;
    }

    public Long getSubMchId() {
        return subMchId;
    }

    public void setSubMchId(Long subMchId) {
        this.subMchId = subMchId;
    }

    public Long getPassageTemplateId() {
        return passageTemplateId;
    }

    public void setPassageTemplateId(Long passageTemplateId) {
        this.passageTemplateId = passageTemplateId;
    }

    public Byte getStatus() {
        return status;
    }

    public void setStatus(Byte status) {
        this.status = status;
    }

    public Integer getRetryCount() {
        return retryCount;
    }

    public void setRetryCount(Integer retryCount) {
        this.retryCount = retryCount;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getApplyInfo() {
        return applyInfo;
    }

    public void setApplyInfo(String applyInfo) {
        this.applyInfo = applyInfo;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", payOrderId=").append(payOrderId);
        sb.append(", payOrderAmount=").append(payOrderAmount);
        sb.append(", payOrderSubject=").append(payOrderSubject);
        sb.append(", channelOrderNo=").append(channelOrderNo);
        sb.append(", smid=").append(smid);
        sb.append(", subMchId=").append(subMchId);
        sb.append(", passageTemplateId=").append(passageTemplateId);
        sb.append(", status=").append(status);
        sb.append(", retryCount=").append(retryCount);
        sb.append(", createTime=").append(createTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", applyInfo=").append(applyInfo);
        sb.append("]");
        return sb.toString();
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        PayAlizftSettRecord other = (PayAlizftSettRecord) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getPayOrderId() == null ? other.getPayOrderId() == null : this.getPayOrderId().equals(other.getPayOrderId()))
                && (this.getPayOrderAmount() == null ? other.getPayOrderAmount() == null : this.getPayOrderAmount().equals(other.getPayOrderAmount()))
                && (this.getPayOrderSubject() == null ? other.getPayOrderSubject() == null : this.getPayOrderSubject().equals(other.getPayOrderSubject()))
                && (this.getChannelOrderNo() == null ? other.getChannelOrderNo() == null : this.getChannelOrderNo().equals(other.getChannelOrderNo()))
                && (this.getSmid() == null ? other.getSmid() == null : this.getSmid().equals(other.getSmid()))
                && (this.getSubMchId() == null ? other.getSubMchId() == null : this.getSubMchId().equals(other.getSubMchId()))
                && (this.getPassageTemplateId() == null ? other.getPassageTemplateId() == null : this.getPassageTemplateId().equals(other.getPassageTemplateId()))
                && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
                && (this.getRetryCount() == null ? other.getRetryCount() == null : this.getRetryCount().equals(other.getRetryCount()))
                && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
                && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
                && (this.getApplyInfo() == null ? other.getApplyInfo() == null : this.getApplyInfo().equals(other.getApplyInfo()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getPayOrderId() == null) ? 0 : getPayOrderId().hashCode());
        result = prime * result + ((getPayOrderAmount() == null) ? 0 : getPayOrderAmount().hashCode());
        result = prime * result + ((getPayOrderSubject() == null) ? 0 : getPayOrderSubject().hashCode());
        result = prime * result + ((getChannelOrderNo() == null) ? 0 : getChannelOrderNo().hashCode());
        result = prime * result + ((getSmid() == null) ? 0 : getSmid().hashCode());
        result = prime * result + ((getSubMchId() == null) ? 0 : getSubMchId().hashCode());
        result = prime * result + ((getPassageTemplateId() == null) ? 0 : getPassageTemplateId().hashCode());
        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
        result = prime * result + ((getRetryCount() == null) ? 0 : getRetryCount().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        result = prime * result + ((getApplyInfo() == null) ? 0 : getApplyInfo().hashCode());
        return result;
    }
}